#!/usr/bin/env node

/**
 * Module dependencies.
 */

var program = require('commander');
var chalk = require('chalk');

function path(val) {
    return val+" in path";
}

function list(val) {
    return val.split(',');
}

program
    .version('0.0.1')
    .option('-C, --chdir <path>', 'change the working directory',path)
    .option('-c, --config <path>', 'set config path. defaults to ./deploy.conf')
    .option('-T, --no-tests', 'ignore test hook')

program
    .command('setup [env]')
    .description('run setup commands for all envs')
    .option("-s, --setup_mode [mode]", "Which setup mode to use")
    .action(function(env, options){
        var mode = options.setup_mode || "normal";
        env = env || 'all';
        console.log('setup for %s env(s) with %s mode', env, mode);
    });

program
    .command('exec <cmd>')
    .alias('ex')
    .description('execute the given remote cmd')
    .option("-e, --exec_mode <mode>", "Which exec mode to use")
    .action(function(cmd, options){
        console.log('exec "%s" using %s mode', cmd, options.exec_mode);
    }).on('--help', function() {
        console.log('  Examples:');
        console.log();
        console.log('    $ deploy exec sequential');
        console.log('    $ deploy exec async');
        console.log();
    });

program
    .command('*')
    .action(function(env){
        console.log('deploying "%s"', env);
    });

program.parse(process.argv);

if(program.chdir){
    console.log('path:', program.chdir);
}

// Try the following:
//   ./main.js -C wong
//   ./main.js help install
//   ./main.js ex wong -e jian
//   ./main.js setup -s jian
//   ./main.js jian

// console.log(chalk.cyan.bold.underline('Name: ' + body.items[i].name));
// console.log(chalk.magenta.bold('Owner: ' + body.items[i].owner.login));
// console.log(chalk.grey('Desc: ' + body.items[i].description + '\n'));
// console.log(chalk.grey('Clone url: ' + body.items[i].clone_url + '\n'));

